using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using Acms.SqlDal;

namespace Acms.Bll
{
    public class Role : BaseItem
    {
        public enum Roles
        {
            Anonomous = -1,
            Registered = -2,
            Administrator = -3,
            Developer = 2,
            MembershipAdministrator = 3,
            ContentEditor = 4,
            MembershipViewer = 5,
            ContentViewer = 6,
            UserGeneratedContentEditor = 7,
            ContentPublisher = 8
        }
        private Role() : base() { }
        private Role(Hashtable table) : base(table) { }
        private Role(Hashtable table, List<Role> collection) : base(table, collection) { }

        protected override Base CreateDal()
        {
            return new RoleDal();
        }

        public static Role CreateInstance()
        {
            return new Role();
        }

        private static Role Get(Hashtable table)
        {
            if (table != null)
                return new Role(table);
            else
                return null;
        }

        private static List<Role> Get(Hashtable[] tables)
        {
            if (tables != null)
            {
                List<Role> tmp = new List<Role>();
                foreach (Hashtable table in tables)
                {
                    tmp.Add(new Role(table, tmp));
                }
                return tmp;
            }
            else
                return null;
        }

        public static List<Role> GetAllBySiteId(int siteId)
        {
            RoleDal dal = new RoleDal();
            return Get(dal.GetAllBySiteId(siteId));
        }

        protected override void Load(Hashtable table)
        {
            id = (int)table[RoleDal.Fields.Id];
            siteId = (int)table[RoleDal.Fields.SiteId];
            name = (string)table[RoleDal.Fields.Name];
            description = (string)table[RoleDal.Fields.Description];
            isAdminRole = (bool)table[RoleDal.Fields.IsAdminRole];
            created = (DateTime)table[RoleDal.Fields.Created];
        }

        private int id;
        public int Id
        {
            get { return id; }
        }

        private int siteId;
        public int SiteId
        {
            get { return siteId; }
        }

        private string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private string description;
        public string Description
        {
            get { return description; }
            set { description = value; }
        }

        private bool isAdminRole;
        public bool IsAdminRole
        {
            get { return isAdminRole; }
            set { isAdminRole = value; }
        }
	

        private DateTime created;
        public DateTime Created
        {
            get { return created; }
        }
    }
}
